<?php

//curl请求
function http_curl($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    if ($error = curl_error($ch)) {
        throw new Exception('http_curl error: ' . $error);
    }
    curl_close($ch);
    return $response;
}

$start_time = strtotime('2010-01-01');
$limit = 10;

while (true) {
	$end_time = time() - 1800;//30分钟前
	$url = 'http://www.yangyueyuan.com/ajax/ordertimeout/updatestatus?' . "end_time={$end_time}" . "&start_time={$start_time}" . "&limit={$limit}";
	$response = json_decode(http_curl($url));
	// var_dump($response);die;
	// 响应不为空，且 该次查询未查到超时订单
	if(! empty($response) && $response->errcode == 1)
	{
		$start_time = $end_time;
	}
	sleep(60);	
}